home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent1 / nsm_tnw041b.lha / tracknameswindow / tnwcontrol.c < prev    next >
C/C++ Source or Header  |  1999-01-30  |  11KB  |  441 lines

  1. /*
  2.     Sets the name of the current track and
  3.     a lot of other things.
  4.  
  5.     Link with annomanno.o, /octacontrol.o
  6.    and /readstr.o to compile.
  7.  
  8.     Made by Kjetil S. Matheussen 19.12.98.
  9.     Last updated: 30.1.98. Changes: Insert track(s) in
  10.     current block didn't work properly. Fixed.
  11.  
  12.     e-mail: kjetilma@ifi.uio.no
  13.  
  14.     Address:
  15.     Kjetil S. Matheussen
  16.     5423 Sogn Studentby
  17.     0858 Oslo
  18.     Norway
  19. */
  20.  
  21.  
  22.  
  23. #include <string.h>
  24. #include "tracknameswindow.h"
  25. #include "/readstr.h"
  26.  
  27. OCTABASE ob;
  28. char *dosbase,*filehandle;
  29. char string[80];
  30. int stringlen;
  31.  
  32. UWORD currtrack,currblock,numtracks,numblocks,numlines,numpages;
  33.  
  34. void setname(void){
  35.     stringlen=strlen(string);
  36.     if(stringlen<10) {
  37.         settrackname(ob,"      ",currtrack,0,currblock);
  38.         settrackname(ob,string,currtrack,4-(stringlen/2),currblock);
  39.     }else{
  40.         settrackname(ob,string,currtrack,0,currblock);
  41.     }
  42.     settracknamedata(ob,currtrack);
  43. }
  44.  
  45.  
  46. void setname_1(void){
  47.     writestring(dosbase,filehandle,"New Name will be: ",18);
  48.     readstring(dosbase,filehandle,string,70);
  49.     if(*string!=NULL) setname();
  50. }
  51.  
  52.  
  53. char plaintrackname[15];
  54. UWORD block,track;
  55. void inserttrackplain(int trackstoinsert){
  56.     sendrexxword("ED_SETBLOCKTRACKS TRACKS ",trackstoinsert+numtracks,"");
  57.  
  58.     for(track=63;track>=currtrack+trackstoinsert;track--)
  59.         settrackname(
  60.             ob,
  61.             gettrackname(ob,track-trackstoinsert,block),
  62.             track,
  63.             0,
  64.             block
  65.         );
  66.  
  67.     for(track=0;track<trackstoinsert;track++){
  68.         sendrexx("RN_INSERTTRACK");
  69.         settrackname(
  70.             ob,
  71.             plaintrackname,
  72.             track+currtrack,
  73.             0,
  74.             block
  75.         );
  76.     }
  77.  
  78. }
  79.  
  80.  
  81. void insert_track_g(void){
  82.     int trackstoinsert=0;
  83.  
  84.     sprintf(string,"How many tracks (globally from current track): ");
  85.     writestring(dosbase,filehandle,string,strlen(string));
  86.     readstring(dosbase,filehandle,string,70);
  87.     sscanf(string,"%d",&trackstoinsert);
  88.     if(trackstoinsert>0 && trackstoinsert+numtracks<64){
  89.  
  90.         sprintf(string,"\n\nPlease wait..: %d",trackstoinsert);
  91.         writestring(dosbase,filehandle,string,strlen(string));
  92.  
  93.         numblocks=getnumblocks(ob);
  94.  
  95.         for(block=currblock;block<numblocks;block++){
  96.             inserttrackplain(trackstoinsert);
  97.             sendrexx("ED_GOTOBLOCK NEXT");
  98.         }
  99.  
  100.         sendrexxword("ED_GOTO BLOCK ",currblock,"");
  101.  
  102.         updatetnw(ob);
  103.     }
  104. }
  105.  
  106. void insert_track(void){
  107.     int trackstoinsert=0;
  108.  
  109.     sprintf(string,"How many tracks to insert (in current track): ");
  110.     writestring(dosbase,filehandle,string,strlen(string));
  111.     readstring(dosbase,filehandle,string,70);
  112.     sscanf(string,"%d",&trackstoinsert);
  113.     if(trackstoinsert>0 && trackstoinsert+numtracks<64){
  114.  
  115.         sprintf(string,"\n\nPlease wait..: %d",trackstoinsert);
  116.         writestring(dosbase,filehandle,string,strlen(string));
  117.  
  118.         block=currblock;
  119.         inserttrackplain(trackstoinsert);
  120.  
  121.         updatetnw(ob);
  122.     }
  123. }
  124.  
  125. void deletetrackname(void){
  126.     for(track=currtrack;track<63;track++)
  127.         settrackname(
  128.             ob,
  129.             gettrackname(ob,track+1,block),
  130.             track,
  131.             0,
  132.             block
  133.         );
  134.     updatetnw(ob);
  135. }
  136.  
  137. void copytracknamesblockplain(int fromblock,int toblock){
  138.     for(track=0;track<=63;track++)
  139.         settrackname(
  140.             ob,
  141.             gettrackname(ob,track,fromblock),
  142.             track,
  143.             0,
  144.             toblock
  145.         );
  146. }
  147.  
  148. void copytracknamesblock(void){
  149.     int toblock;
  150.  
  151.     sprintf(string,"Which block to copy: ");
  152.     writestring(dosbase,filehandle,string,strlen(string));
  153.     readstring(dosbase,filehandle,string,70);
  154.     sscanf(string,"%x",&toblock);
  155.  
  156.     if(toblock>0 && toblock!=currblock && toblock<=numblocks){
  157.         sendrexxword("ED_GOTO BLOCK ",toblock,"");
  158.         copytracknamesblockplain(currblock,toblock);
  159.         updatetnw(ob);
  160.     }
  161. }
  162.  
  163. void copyblock(void){
  164.     int toblock;
  165.  
  166.     sprintf(string,"Which block to copy: ");
  167.     writestring(dosbase,filehandle,string,strlen(string));
  168.     readstring(dosbase,filehandle,string,70);
  169.     sscanf(string,"%x",&toblock);
  170.  
  171.     if(toblock>0 && toblock!=currblock && toblock<=numblocks){
  172.         sendrexx("RN_COPY BLOCK");
  173.         sendrexxword("ED_GOTO BLOCK ",toblock,"");
  174.         sendrexx("RN_PASTE BLOCK");
  175.         copytracknamesblockplain(currblock,toblock);
  176.         updatetnw(ob);
  177.     }
  178. }
  179.  
  180.  
  181. void addblockplainnames(void){
  182.     FILE *plainnamestemp;
  183.     int block,track,track10,track1;
  184.  
  185.     plainnamestemp=fopen("nsm:plainnamestempcontrol","w");
  186.  
  187.     fprintf(plainnamestemp,"%s\n",gettrackname(ob,(UWORD)-2,0));
  188.     fprintf(plainnamestemp,"%s\n",gettrackname(ob,(UWORD)-1,0));
  189.  
  190.     for(block=0;block<numblocks;block++)
  191.         for(track=0;track<64;track++)
  192.             fprintf(plainnamestemp,"%s\n",gettrackname(ob,track,block));
  193.  
  194.     for(track10=0;track10<6;track10++)
  195.         for(track1=0;track1<10;track1++)
  196.             fprintf(plainnamestemp,"\03  %d%d     \n",track10,track1);
  197.  
  198.     fprintf(plainnamestemp,"\03  60     \n");
  199.     fprintf(plainnamestemp,"\03  61     \n");
  200.     fprintf(plainnamestemp,"\03  62     \n");
  201.     fprintf(plainnamestemp,"\03  63     \n");
  202.  
  203.     fclose(plainnamestemp);
  204.  
  205.     sendrexx("SG_LOADANNOTEXT \"nsm:plainnamestempcontrol\"");
  206.  
  207. }
  208.  
  209.  
  210. void insertblock(void){
  211.     char string2[80]="ED_SETBLOCKNAME \"";
  212.  
  213.     if(gettrackname(ob,10,numblocks)==0){
  214.         writestring(dosbase,filehandle,"\nPlease wait, initializing new tracknamesblock. ",50);
  215.         addblockplainnames();
  216.         writestring(dosbase,filehandle,"\nFinished! ",11);
  217.     }
  218.  
  219.     sendrexxword("ED_GOTO BLOCK ",currblock+1,"");
  220.  
  221.     sendrexxword3(
  222.         "ED_NEWBLOCK INSERT TRACKS ",numtracks,
  223.         " LINES ",numlines,
  224.         " PAGES ",numpages+1,""
  225.     );
  226.  
  227.  
  228.     writestring(dosbase,filehandle,"\n\nName of the new block: ",25);
  229.     readstring(dosbase,filehandle,string,50);
  230.     if(*string!=0){
  231.         strcat(string2,string);
  232.         strcat(string2,"\"");
  233.         sendrexx(string2);
  234.     }
  235.  
  236.     for(block=currblock;block<numblocks-1;block++)
  237.         copytracknamesblockplain(block,block+1);
  238.  
  239.     for(track=0;track<64;track++)
  240.         settrackname(
  241.             ob,
  242.             plaintrackname,
  243.             track,
  244.             0,
  245.             currblock+1
  246.         );
  247.  
  248.     updatetnw(ob);
  249. }
  250.  
  251. void appendblock(void){
  252.     char string2[80]="ED_SETBLOCKNAME \"";
  253.  
  254.     sendrexxword3(
  255.         "ED_NEWBLOCK LAST TRACKS ",numtracks,
  256.         " LINES ",numlines,
  257.         " PAGES ",numpages+1,""
  258.     );
  259.  
  260.     sendrexxword("ED_GOTO BLOCK ",numblocks,"");
  261.  
  262.     writestring(dosbase,filehandle,"\n\nName of the new block: ",25);
  263.     readstring(dosbase,filehandle,string,50);
  264.     if(*string!=0){
  265.         strcat(string2,string);
  266.         strcat(string2,"\"");
  267.         sendrexx(string2);
  268.     }
  269. }
  270.  
  271.  
  272. void resettrackname(void){
  273.     settrackname(
  274.         ob,
  275.         plaintrackname,
  276.         currtrack,
  277.         0,
  278.         currblock
  279.     );
  280.     updatetnw(ob);
  281. }
  282.  
  283. void deletecurrtracknames(void){
  284.     for(block=currblock+1;block<numblocks;block++)
  285.         copytracknamesblockplain(block,block-1);
  286.     updatetnw(ob);
  287. }
  288.  
  289. void deleteblock(void){
  290.     sendrexx("ED_DELETEBLOCK");
  291.     deletecurrtracknames();
  292. }
  293.  
  294. void swaptrack(void){
  295.  
  296.     if(currtrack<numtracks-1){
  297.  
  298.         sendrexx("RN_COPY TRACK");
  299.  
  300.         sendrexx("ED_GOTOTRACK NEXTNOTE");
  301.         sendrexx("RN_SWAP TRACK");
  302.  
  303.         sendrexx("ED_GOTOTRACK PREVNOTE");
  304.         sendrexx("RN_SWAP TRACK");
  305.  
  306.  
  307.         strcpy(string,gettrackname(ob,currtrack,currblock));
  308.         settrackname(
  309.             ob,
  310.             gettrackname(ob,currtrack+1,currblock),
  311.             currtrack,
  312.             0,
  313.             currblock
  314.         );
  315.  
  316.         settrackname(
  317.             ob,
  318.             string,
  319.             currtrack+1,
  320.             0,
  321.             currblock
  322.         );
  323.         updatetnw(ob);
  324.  
  325.     }
  326. }
  327.  
  328. void main(){
  329.     BLOCKBASE bb;
  330.  
  331.     char *ver="$VER: tnwcontrol 0.41b.300199 (30.1.99) by Kjetil S. Matheussen";
  332.  
  333.     if((ob=getoctabase())==0) goto exit;
  334.  
  335.     dosbase=opendoslibrary();
  336.     filehandle=openoctacon(dosbase,500,200);
  337.  
  338.     currtrack=getcurrtrack(ob);
  339.     currblock=getcurrblock(ob);
  340.     numblocks=getnumblocks(ob);
  341.     bb=getblockbase(ob,currblock);
  342.     numtracks=getnumtracks(bb);
  343.     numlines=getnumlines(bb);
  344.     numpages=getnumpages(bb);
  345.     sprintf(plaintrackname,"\03             ");
  346.  
  347.     if(strcmp(gettrackname(ob,(UWORD)-2,0),"QNM")){
  348.         sendrexx("SG_LOADANNOTEXT \"nsm:plainnames\"");
  349.         updatetnw(ob);
  350.     }
  351.  
  352.     sprintf(string,"Track %d has the current name: \"%s\"\n\n",currtrack,gettrackname(ob,currtrack,0));
  353.     writestring(dosbase,filehandle,string,strlen(string));
  354.  
  355.     sprintf(string,"Choose option: (write number and press return)\n\n");
  356.     writestring(dosbase,filehandle,string,strlen(string));
  357.  
  358.     sprintf(string,"1. Set trackname (default, just write name)\n");
  359.     writestring(dosbase,filehandle,string,strlen(string));
  360.  
  361.     sprintf(string,"2. Insert track(s) in all blocks from current block\n");
  362.     writestring(dosbase,filehandle,string,strlen(string));
  363.  
  364.     sprintf(string,"3. Insert track(s) in current block\n");
  365.     writestring(dosbase,filehandle,string,strlen(string));
  366.  
  367.     sprintf(string,"4. Delete current trackname in current block\n");
  368.     writestring(dosbase,filehandle,string,strlen(string));
  369.  
  370.     sprintf(string,"5. Copy current block to another block\n");
  371.     writestring(dosbase,filehandle,string,strlen(string));
  372.  
  373.     sprintf(string,"6. Copy just tracknames of current block to another block\n");
  374.     writestring(dosbase,filehandle,string,strlen(string));
  375.  
  376.     sprintf(string,"7. Insert New block. \n");
  377.     writestring(dosbase,filehandle,string,strlen(string));
  378.  
  379.     sprintf(string,"8. Append New block\n");
  380.     writestring(dosbase,filehandle,string,strlen(string));
  381.  
  382.     sprintf(string,"9. Delete Current block\n");
  383.     writestring(dosbase,filehandle,string,strlen(string));
  384.  
  385.     sprintf(string,"A. Delete just the tracknames of the current block\n");
  386.     writestring(dosbase,filehandle,string,strlen(string));
  387.  
  388.     sprintf(string,"B. Delete Last block\n");
  389.     writestring(dosbase,filehandle,string,strlen(string));
  390.  
  391.     sprintf(string,"C. Swap current track with next\n");
  392.     writestring(dosbase,filehandle,string,strlen(string));
  393.  
  394.     sprintf(string,"D. Resets the current trackname to default\n");
  395.     writestring(dosbase,filehandle,string,strlen(string));
  396.  
  397. /*
  398.     sprintf(string,"\n");
  399.     writestring(dosbase,filehandle,string,strlen(string));
  400.     sprintf(string,"\n");
  401.     writestring(dosbase,filehandle,string,strlen(string));
  402.     sprintf(string,"\n");
  403.     writestring(dosbase,filehandle,string,strlen(string));
  404. */
  405.  
  406.     sprintf(string,"\n> ");
  407.     writestring(dosbase,filehandle,string,strlen(string));
  408.  
  409.     readstring(dosbase,filehandle,string,70);
  410.  
  411.  
  412.     if(!strcmp(string,"1")){setname_1();goto close;}
  413.     if(!strcmp(string,"2")){insert_track_g();goto close;}
  414.     if(!strcmp(string,"3")){insert_track();goto close;}
  415.     if(!strcmp(string,"4")){block=currblock;deletetrackname();goto close;}
  416.     if(!strcmp(string,"5")){copyblock();goto close;}
  417.     if(!strcmp(string,"6")){copytracknamesblock();goto close;}
  418.     if(!strcmp(string,"7")){insertblock();goto close;}
  419.     if(!strcmp(string,"8")){appendblock();goto close;}
  420.     if(!strcmp(string,"9")){deleteblock();goto close;}
  421.     if(!strcmp(string,"a") || !strcmp(string,"A") ){deletecurrtracknames();goto close;}
  422.     if(!strcmp(string,"b") || !strcmp(string,"B") ){sendrexx("ED_DELETEBLOCK LAST");goto close;}
  423.     if(!strcmp(string,"c") || !strcmp(string,"C") ){swaptrack();goto close;}
  424.     if(!strcmp(string,"d") || !strcmp(string,"D") ){resettrackname();goto close;}
  425.  
  426. /*
  427.     if(!strcmp(string,"C")){goto close;}
  428.     if(!strcmp(string,"D")){goto close;}
  429. */
  430.  
  431.     if(*string!=NULL) setname();
  432.  
  433. close:
  434.     closefile(dosbase,filehandle);
  435.     closedoslibrary(dosbase);
  436.  
  437. exit:
  438. }
  439.  
  440.  
  441.